﻿using UnityEngine;
using System.Collections;

public class UpdateApp : MonoBehaviour
{
    public static UpdateApp instance;
    public GameObject bgPanel;
    public GameObject updatePanel;  

    private string updateUrl = "http://bbs.520ar.com/mashi/chengyu/version.txt";

    void Awake()
    {
        instance = this;
        StartCoroutine( version() );
        


    } 
    void Start()
    {
        
        //bgPanel.SetActive( true );
    }

    // Update is called once per frame
    void Update()
    {
        
    }    

    public IEnumerator version( )
    {
       WWW www = new WWW( updateUrl );
        //Debug.LogError( "www:" + www.text );

        yield return www;
        while( !www.isDone )
        {
            yield return null;
        }
        if (www.error == null && www.text != null)
        {
            string[] wwwdata = www.text.Split(',');
            string[] serVerlist = (wwwdata[0]).Split('.');//服务器上version版本  
            int serVer = int.Parse(serVerlist[2]);
            string[] locVerlist = Application.version.Split('.');
            int locVer = int.Parse(locVerlist[2]);

            if (locVer >= serVer)
            {
                bgPanel.SetActive(true);
                Debug.Log("当前版本已是最新!");
            }
            else
            {
                bgPanel.SetActive(false);
                updatePanel.gameObject.SetActive(true);
                Debug.Log("app已经远程关闭，如需打开app联系开发者！");
            }
        }
        else
        {
            bgPanel.SetActive(true);
            Debug.Log("当前版本已是最新!");
        }

    }   
  
}
